local rentu = fk.CreateSkill{
  name = "lingling__rentu",
}

Fk:loadTranslationTable{
  ["lingling__rentu"] = "人屠",
  [":lingling__rentu"] = "出牌阶段，你可以弃置一张本阶段未以此法弃置的花色的牌，若如此做，你对一名体力/手牌为1的角色造成1点伤害，"..
  "然后其回复1点体力/摸一张牌，你摸两张牌。",

  ["#lingling__rentu"] = "人屠：弃一张牌，然后对一名体力或手牌数为1的角色造成1点伤害",
  ["lingling__rentu-hp"] = "对一名体力为1的角色造成伤害，然后其回复1点体力，你摸两张牌",
  ["lingling__rentu-hand"] = "对一名手牌为1的角色造成伤害，然后其摸一张牌，你摸两张牌",
  ["@lingling__rentu-phase"] = "人屠",
}

rentu:addEffect("active", {
  anim_type = "offensive",
  prompt = "#lingling__rentu",
  card_num = 1,
  target_num = 0,
  card_filter = function (self, player, to_select, selected)
    return #selected == 0 and not player:prohibitDiscard(to_select) and
      not table.contains(player:getTableMark("@lingling__rentu-phase"), Fk:getCardById(to_select):getSuitString(true))
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    room:addTableMark(player, "@lingling__rentu-phase", Fk:getCardById(effect.cards[1]):getSuitString(true))
    room:throwCard(effect.cards, rentu.name, player, player)
    if player.dead then return end
    local targets1 = table.filter(room.alive_players, function (p)
      return p.hp == 1
    end)
    local targets2 = table.filter(room.alive_players, function (p)
      return p:getHandcardNum() == 1
    end)
    local choices = {}
    if #targets1 > 0 then
      table.insert(choices, "lingling__rentu-hp")
    end
    if #targets2 > 0 then
      table.insert(choices, "lingling__rentu-hand")
    end
    if #choices == 0 then return end
    local choice = room:askToChoice(player, {
      choices = choices,
      skill_name = rentu.name,
    })
    local target
    if choice == "lingling__rentu-hp" then
      target = room:askToChoosePlayers(player, {
        min_num = 1,
        max_num = 1,
        targets = targets1,
        skill_name = rentu.name,
        prompt = "lingling__rentu-hp",
        cancelable = false,
      })[1]
    else
      target = room:askToChoosePlayers(player, {
        min_num = 1,
        max_num = 1,
        targets = targets2,
        skill_name = rentu.name,
        prompt = "lingling__rentu-hand",
        cancelable = false,
      })[1]
    end
    room:damage{
      from = player,
      to = target,
      damage = 1,
      skillName = rentu.name,
    }
    if not target.dead then
      if choice == "lingling__rentu-hp" then
        room:recover{
          who = target,
          num = 1,
          recoverBy = player,
          skillName = rentu.name,
        }
      else
        target:drawCards(1, rentu.name)
      end
    end
    if not player.dead then
      player:drawCards(2, rentu.name)
    end
  end,
})

rentu:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, "lingling__rentu-phase", 0)
end)

return rentu
